import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext import blobstore

class Country(db.Model):
    CountryName = db.StringProperty(required = True)
    
class Role(db.Model):
    RoleName = db.StringProperty(required=True)
    
class User(db.Model):
    UserName = db.UserProperty()
    FullName = db.StringProperty(required = True)
    Email = db.StringProperty(required = True)
    Mobile = db.StringProperty(required = True)
    RoleID = db.ReferenceProperty(Role, required=True,collection_name = 'ref_Role_Dev')   
    
class Version(db.Model):
    VersionName = db.StringProperty(required = True)

class Device(db.Model):
    DeviceName = db.StringProperty(required = True)

class Developer(db.Model):
    UserID = db.ReferenceProperty(User, required=True,collection_name = 'ref_User_Dev')
    CountryID =  db.ReferenceProperty(Country, required=True,collection_name = 'ref_Country_Dev')
    Address1 = db.StringProperty(required = True)
    Address2 = db.StringProperty()
    City = db.StringProperty(required = True)
    Province = db.StringProperty(required = True)
    PostalCode = db.StringProperty(required = True)
    Company = db.StringProperty(required = True)
    Website = db.StringProperty(required = True)
    PaypalAccount = db.StringProperty(required = True)
    
class Customer(db.Model):
    Avatar = db.BlobProperty()
    UserID = db.ReferenceProperty(User, required=True,collection_name = 'ref_User_Customer')
    
class Category(db.Model):
    CategoryName = db.StringProperty(required = True)  
    
class Language(db.Model):
    LanguageName = db.StringProperty(required = True)  
    
class App(db.Model):
    Title = db.StringProperty(required = True)
    AppName = db.StringProperty(required = True) 
    Description = db.TextProperty(required = True)  
    Price = db.FloatProperty(required = True) 
    KeyWord = db.StringProperty(required = True)  
    LanguageID =  db.ReferenceProperty(Language, required=True,collection_name = 'ref_Language_App')
    CategoryID = db.ReferenceProperty(Category,required=True)
    DeviceID = db.ReferenceProperty(Device,required=True)
    DevID = db.ReferenceProperty(Developer,required=True)
    ReleaseDate = db.DateTimeProperty(required = True)
    VersionID = db.ReferenceProperty(Version,required = True) 
    AppIcon = blobstore.BlobReferenceProperty()
    AppScreenShot = blobstore.BlobReferenceProperty()
    DownloadNumber = db.IntegerProperty()
    AppSource = blobstore.BlobReferenceProperty(required=True)

class Customer_App(db.Model):
    CustomerID = db.ReferenceProperty(Customer, required=True,collection_name = 'ref_Customer_CusApp')
    AppID = db.ReferenceProperty(App, required=True,collection_name = 'ref_App_CusApp')
    DateBuy = db.DateTimeProperty(required=True)
    
class AppComment(db.Model):
    CommentContent = db.StringProperty(required = True)
    Votes  = db.IntegerProperty(default = 0)
    AppID = db.ReferenceProperty(App, required=True,collection_name = 'ref_App_AppCom')
    CustomerName = db.UserProperty(required = True)
    DatePost = db.DateTimeProperty(required=True)
    
class Source(db.Model):
    StoreSource = blobstore.BlobReferenceProperty(required=True)
    Version = db.StringProperty(required = True)




    